﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

//单位锁死时的类型是什么
public enum SoldierLockingtype
{
    None, ToDie, HitFly,Defend
}


/// <summary>
/// 单位锁住（击飞，死亡）时，用来控制单位的控制器，包括击飞
/// </summary>
public class LockController : BattleComponent<LockController> {
    public SoldierAI ai;
    
    public SoldierVehicle soldierVehicle;
    public NavMeshAgent navMeshAgent;
    public Collider coll;

    private Rigidbody rb;

    //单位锁死时的类型
    public SoldierLockingtype lockingtype;
    public float hitFlytime;
    public Vector3 hitFlyForce;

    public void Start()
    {
        
    }

    public void OnEnable()
    {
        Assign(this);
    }

    public void OnDisable()
    {
        Assign(this);
    }

    public void HitFly()
    {
        

        if (rb == null) rb = gameObject.AddComponent<Rigidbody>();
        rb.useGravity = true;
        coll.isTrigger = false;
        
        rb.AddForce(hitFlyForce);
        rb.constraints = RigidbodyConstraints.FreezeRotation;

        
    }

    public void Retrive()
    {
        if (rb != null) Destroy(rb);
        coll.isTrigger = true;
    }



}
